package com.sumainfor.wx.system.maket.controller.rentadviser;

import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.wx.system.feign.BaseFeignMarket;
import com.sumainfor.wx.system.maket.service.RdPactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 合同
 * <p>
 *
 * @author: zc
 * @create: 2019-08-16 14:31
 **/
@Controller
@RequestMapping("/RdPactController")
public class RdPactController {

    @Autowired
    RdPactService rdPactService;

    @Autowired
    BaseFeignMarket baseFeignMarket;




    /**
     * 今日已签约
     * @author zhoucong
     * @data 2019/8/16
     * @Param
     * @return
     */
    @ResponseBody
    @GetMapping("/getPactListById")
    public JsonResult getPactListById(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params ,new String[]{"StateNow"})){
             result.putFailed("服务器繁忙...");
        }
        params.put("UserId", ContextUtils.getUserId());

        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdPactService.getPactListCountById(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getCommunityList=rdPactService.getPactListById(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }



    /**
     * 签约时查看客户签约的合同
     * @author zhoucong
     * @data 2019/8/19
     * @Param
     * @return
     */
    @ResponseBody
    @GetMapping("/getPactListByTenId")
    public JsonResult getPactListByTenId(@RequestParam Map<String,Object> params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=rdPactService.getPactListByTenId(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 发起签约
     * @author zhoucong
     * @data 2019/8/19
     * @Param
     * @return
     */
    @ResponseBody
    @PostMapping("/addPact")
    public JsonResult addPact(@RequestBody Map<String,Object> params){
        return baseFeignMarket.addPact(params);
    }
}
